<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 微信会员卡-会员列表数据
 * @package App\Models
 */
class WxCardMemberList extends Model
{
    use SoftDeletes;
    protected $table = 'wx_card_member_lists';
    //主键
    protected $primaryKey = 'id';
    protected $dateFormat = 'Y-m-d H:i:s';
    /**
     * 需要转换成日期的属性
     * @var array
     */
    protected $dates = [

    ];
    /**
     * 应该被转换成原生类型的属性。
     * @var array
     */
    protected $casts = [
        'user_info' => 'array',
    ];

    /**
     * 微信卡券数据
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function card()
    {
        return $this->belongsTo('App\Models\WxCardBase','card_base_id','card_base_id');
    }
    /**
     * 微信用户数据模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function user()
    {
        return $this->hasOne('App\Models\WxUser','openid', 'openid');
    }

    /**
     * 微信卡券领取数据模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function receive()
    {
        return $this->hasOne('App\Models\WxCardReceive','user_card_code', 'user_card_code');
    }
    /**
     * 会员等级模型关联
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function level()
    {
        return $this->belongsTo('App\Models\WxCardMemberLevel','level_id','id');
    }
}
